{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "b14a24db",
   "metadata": {},
   "source": [
    "# FireworksEmbeddings\n",
    "\n",
    "This notebook explains how to use Fireworks Embeddings, which is included in the langchain_fireworks package, to embed texts in langchain. We use the default nomic-ai v1.5 model in this example."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0ab948fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install -qU langchain-fireworks"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "67c637ca",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5709b030",
   "metadata": {},
   "outputs": [],
   "source": [
    "from langchain_fireworks import FireworksEmbeddings"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3d81e58c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import getpass\n",
    "import os\n",
    "\n",
    "if \"FIREWORKS_API_KEY\" not in os.environ:\n",
    "    os.environ[\"FIREWORKS_API_KEY\"] = getpass.getpass(\"Fireworks API Key:\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a2a098d",
   "metadata": {},
   "source": [
    "# Using the Embedding Model\n",
    "With `FireworksEmbeddings`, you can directly use the default model 'nomic-ai/nomic-embed-text-v1.5', or set a different one if available."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "584b9af5",
   "metadata": {},
   "outputs": [],
   "source": [
    "embedding = FireworksEmbeddings(model=\"nomic-ai/nomic-embed-text-v1.5\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "be18b873",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.01367950439453125, 0.0103607177734375, -0.157958984375, -0.003070831298828125, 0.05926513671875]\n",
      "[0.0369873046875, 0.00545501708984375, -0.179931640625, -0.018707275390625, 0.0552978515625]\n"
     ]
    }
   ],
   "source": [
    "res_query = embedding.embed_query(\"The test information\")\n",
    "res_document = embedding.embed_documents([\"test1\", \"another test\"])\n",
    "print(res_query[:5])\n",
    "print(res_document[1][:5])"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "poetry-venv-2",
   "language": "python",
   "name": "poetry-venv-2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
